package com.yunbao.hujin.myguidepage.guide;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

import com.yunbao.hujin.myguidepage.BaseActivity;
import com.yunbao.hujin.myguidepage.MainActivity;
import com.yunbao.hujin.myguidepage.R;
import com.yunbao.hujin.myguidepage.adapter.GuideAdapter;
import com.yunbao.hujin.myguidepage.view.PageIndicatorView;

import java.util.Timer;
import java.util.TimerTask;

public class GuideActivity extends BaseActivity {

    private ViewPager viewPager;
    private PageIndicatorView pageIndicatorView;
    private TextView jump;

    private int guideImg[] = {R.mipmap.guide_01, R.mipmap.guide_02, R.mipmap.guide_03};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);          //隐藏标题栏
        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;  //定义全屏参数
        Window window = this.getWindow();                       //获得当前窗体对象
        window.setFlags(flag, flag);                            //设置当前窗体为全屏显示

        setContentView(R.layout.activity_guide);
        initView();
    }

    private void initView() {
        viewPager = findViewById(R.id.view_pager);
        pageIndicatorView = findViewById(R.id.indicator);
        jump = findViewById(R.id.jump);

        pageIndicatorView.initIndicator(3);
        GuideAdapter adapter = new GuideAdapter(this, guideImg);
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(0);

        //page监听
        pagerChangeListener();

        jump.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startMainActivity();
            }
        });
    }

    private void pagerChangeListener() {
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                pageIndicatorView.setSelectedPage(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


    //跳转到主界面
    public void startMainActivity() {
        saveFirst();
        startActivity(new Intent(this, MainActivity.class));
        overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
        finish();
    }


}
